package ui 
{
	import data.GCShipData;
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.TextEvent;
	import ui.textfield.GCTextField;
	import ui.textfield.GCStylizedText;
	
	/**
	 * A component to display various statistics about the
	 * player's ship.
	 */
	public class GCShipStatsArea extends Sprite 
	{
		private static const LEFT_OFFSET:int = 20;
		private static var LABEL_HEIGHT:int = 50;
		
		private var _stats:Vector.<uint>;
		private var _statsDisplay:Vector.<GCStylizedText>;
		
		private var _backgroundImage:Sprite;
		
		public function GCShipStatsArea() 
		{			
			_backgroundImage = GCResources.getMaskedCanvasBackground(310, 330);
			this.addChildAt(_backgroundImage, 0);
			
			_stats = new Vector.<uint>(GCShipData.NUM_STATS);
			_statsDisplay = new Vector.<GCStylizedText>(GCShipData.NUM_STATS);
			for (var i:uint = 0; i < GCShipData.NUM_STATS; i++) {
				_statsDisplay[i] = new GCStylizedText();
			}
			
			init();
		}
		
		public function initializeStats(stats:Vector.<uint>):void
		{
			for (var i:uint = 0; i < GCShipData.NUM_STATS; i++) {
				changeStat(i, stats[i]);
			}
		}
		
		public function changeStat(stat:uint, value:uint):void {
			_stats[stat] = value;
			_statsDisplay[stat].text = String(value);
		}
		
		private function init():void
		{
			trace("initialized the stats");
			
			for (var i:uint = 0; i < GCShipData.NUM_STATS; i++) {
				var label:GCTextField = new GCTextField();
				label.text = GCShipData.getStatName(i);
				label.height = LABEL_HEIGHT;
				label.x = LEFT_OFFSET;
				if (i == 0)
					label.y = 15;
				else
					label.y = _statsDisplay[i - 1].y + LABEL_HEIGHT;
				
				_statsDisplay[i].x = label.x + label.width;
				_statsDisplay[i].y = label.y;
				_statsDisplay[i].setBgStyle(GCStylizedText.STYLE_ONE, 150,  label.height);
				
				this.addChild(label);
				this.addChild(_statsDisplay[i]);
			}
		}
		
	}

}